from random import randint

def mprint(m):
	return '\n'.join(map(lambda x:''.join([el and '#' or '_' for el in x]),m))

fout=open('test_sanos.in','w')

for n in range(6,40):
	for caso in range(10):
		M=[[0]*n for el in range(n)]
		ks=[]
		for cuad in range(randint(5,2*n)):
			ki=randint(2,n/4+1)
			if ki%2==1: ki+=randint(0,10)<5 and 1 or -1
			kj=randint(2,n/4+1)
			i,j=randint(0,n-ki),randint(0,n-kj)
			ok=True
			for unki,unkj,uni,unj in ks:
				#if (unj-1<=j<=unkj+unj+1 and uni-1<=i<=unki+uni+1) or (unj-1<=kj+j<=unkj+unj+1 and uni-1<=ki+i<=unki+uni+1) or (unj-1<=kj+j<=unkj+unj+1 and uni-1<=i<=unki+uni+1)  or (unj-1<=j<=unkj+unj+1 and uni-1<=ki+i<=unki+uni+1): ok=False
				for ii in range(i,i+ki):
					for jj in range(j,j+kj):
						if M[ii][jj] or (ii<n-1 and M[ii+1][jj]) or (jj<n-1 and M[ii][jj+1]) or (ii>0 and M[ii-1][jj]) or (jj>0 and M[ii][jj-1]): ok=False
			if ok:
				ks.append((ki,kj,i,j))
				for p in range(i,i+ki):
					for l in range(j,j+kj):
						M[p][l]=1
		fout.write(str(n)+"\n"+mprint(M)+"\n")

fout.write("-1\n\n")
